package day1107;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;

import static common.PrintUtil.printLine;

/**
 * @author Mr.ma
 * @since 2022/11/7 17:35
 * jdk8新特性提供了新的本地化时间API（构造方法私有化）：
 *      LocalDate,LocalTime,LocalDateTime
 * API常用方法有；
 *      now(),toLocalDate(),of(),parse()
 *      getMonth(),getDayOfMonth(),getYear(),getSecond()
 *      withDayOfMonth(),withYear()
 **/
public class CreateLocalDate {
    public static void main(String[] args) {
        printLine("获取当前日期");
        LocalDate nowDate = LocalDate.now();
        System.out.println("nowDate = " + nowDate);
        printLine("获取当前时间");
        LocalTime nowTime = LocalTime.now();
        System.out.println("nowTime = " + nowTime);
        printLine("获取当前日期及时间");
        LocalDateTime nowDateTime = LocalDateTime.now();
        System.out.println("nowDateTime = " + nowDateTime);
        printLine("分别获取当前日期的年月日");
        int year = nowDate.getYear();
        int monthValue = nowDate.getMonthValue();
        int dayOfMonth = nowDate.getDayOfMonth();
        System.out.println(year + "年" + monthValue + "月" + dayOfMonth + "日");
        printLine("修改日期");
        LocalDate editDate = nowDate.withDayOfMonth(10);
        System.out.println("editDate = " + editDate);
        printLine("自定义时间");
        LocalTime customTime = LocalTime.of(15, 14, 45);
        System.out.println("customTime = " + customTime);
        printLine("获取自定义时间的时分秒");
        int hour = customTime.getHour();
        System.out.println("时 = " + hour);
        int minute = customTime.getMinute();
        System.out.println("分 = " + minute);
        int second = customTime.getSecond();
        System.out.println("秒 = " + second);
    }
}
